package vip.kqsy.cloud.blog.server.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import vip.kqsy.cloud.blog.server.mapper.CarouselMapper;
import vip.kqsy.cloud.blog.server.pojo.dto.CarouselAddDTO;
import vip.kqsy.cloud.blog.server.pojo.dto.PageCarouselDTO;
import vip.kqsy.cloud.blog.server.pojo.entity.Carousel;
import vip.kqsy.cloud.blog.server.pojo.vo.PageCarouselVO;
import vip.kqsy.cloud.blog.server.service.CarouselService;
import vip.kqsy.cloud.core.web.res.ResPage;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cenjunjie
 * @since 2023-06-23
 */
@Service
public class CarouselServiceImpl extends ServiceImpl<CarouselMapper, Carousel> implements CarouselService {

    @Override
    public void add(CarouselAddDTO dto) {
        Carousel carousel = BeanUtil.toBean(dto, Carousel.class);
        carousel.setCreateTime(LocalDateTime.now());
        save(carousel);
    }

    @Override
    public ResPage<PageCarouselVO> page(PageCarouselDTO dto) {
        PageHelper.startPage(dto);
        List<Carousel> list = lambdaQuery().eq(Objects.nonNull(dto.getRemark()), Carousel::getRemark, dto.getRemark())
                .list();
        return ResPage.of(list).convertListType(PageCarouselVO.class);
    }

}
